home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / applic / NCSA_Telnet / Mac / Telnet2.5 / Telnet2.5src.sit.hqx / Telnet2.5 final / telpass ƒ / tel1.c next >
Encoding:
C/C++ Source or Header  |  1991-12-23  |  19.8 KB  |  910 lines

  1.  
  2. /*
  3. *  NCSA Telnet source code
  4. *  National Center for Supercomputing Applications
  5. *  January 31, 1988
  6. *  (C) Copyright 1988 Board of Trustees of the University of Illinois
  7. *
  8. *  Permission is granted to any individual or institution to use, copy,
  9. *  modify, or redistribute this software and its documentation provided
  10. *  this notice and the copyright notices are retained.  This software
  11. *  may not be distributed for profit, either in original form or in
  12. *  derivative works.  The University of Illinois makes no representations
  13. *  about the suitability of this software for any purpose.  
  14. *  THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY,
  15. *  EITHER EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  16. *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND WARRANTY
  17. *  OF FITNESS FOR A PARTICULAR PURPOSE.
  18. */
  19. /*
  20.  * File Telpass.c
  21.  *
  22.  * Tim Krauskopf
  23.  * Copyright ⌐ 1988 Board of Trustees of the University of Illinois
  24.  *
  25.  * Portions Copyright Apple Computer, Inc. 1985, 1986
  26.  * All rights reserved.
  27.  *
  28.  * Edit passwords for NCSA telnet.  Passwords stored in the data fork of an independent
  29.  * password file.
  30.  *
  31.  */
  32.  
  33. # include <types.h>                 /* Nearly always required */
  34. # include <quickdraw.h>             /* To access the qd globals */
  35. # include <toolutils.h>             /* CursHandle and iBeamCursor */
  36. # include <fonts.h>                 /* Only for InitFonts() trap */
  37. # include <events.h>                /* GetNextEvent(), ... */
  38. #include <OSEvents.h>                /* FlushEvents */
  39. # include <windows.h>                /* GetNewWindow(), ... */
  40. # include <controls.h>
  41. # include <lists.h>
  42. # include <files.h>
  43. # include <packages.h>
  44. # include <dialogs.h>                /* InitDialogs() and GetNewDialog() */
  45. # include <menus.h>                 /* EnableItem(), DisableItem() */
  46. # include <desk.h>                    /* SystemTask(), SystemClick() */
  47. # include <textedit.h>                /* TENew() */
  48. # include <scrap.h>                 /* ZeroScrap() */
  49. # include <segload.h>                /* UnloadSeg() */
  50.  
  51. # include <fcntl.h>
  52. # include <StdIO.h>
  53. #include <string.h>
  54. extern _DataInit();
  55.  
  56. /*
  57.  * Resource ID constants.
  58.  */
  59. # define appleID        128             /* This is a resource ID */
  60. # define fileID         129             /* ditto */
  61. # define editID         130             /* ditto */
  62.  
  63. # define appleMenu        0                /* MyMenus[] array indexes */
  64. # define    aboutMeCommand    1
  65.  
  66. # define fileMenu        1
  67. # define    newCommand  1
  68. # define    openCommand 2
  69. # define    saveCommand 3
  70. # define    saveasCommand 4
  71. # define    quitCommand 5
  72.  
  73. # define editMenu        2
  74. # define    undoCommand     1
  75. # define    cutCommand        3
  76. # define    copyCommand     4
  77. # define    pasteCommand    5
  78. # define    clearCommand    6
  79.  
  80. # define menuCount     3
  81. /*
  82.  * For the one and only text window
  83.  */
  84. # define windowID        128
  85. #define drawinID  129
  86. /*
  87.  * For the About Sample... DLOG
  88.  */
  89. # define aboutMeDLOG    128
  90. # define newuDLOG  129
  91. # define newpDLOG  130
  92. # define delDLOG 131
  93.  
  94. # define    okButton        1
  95. /*
  96. *  For the controls
  97. */
  98. #define Cnewuser 129
  99. #define Cdelete 130
  100. #define Cpasswd 131
  101. #define NCS 3
  102.  
  103. # define SETRECT(rectp, _top, _left,  _bottom, _right)    \
  104.     (rectp)->left = (_left), (rectp)->top = (_top),     \
  105.     (rectp)->right = (_right), (rectp)->bottom = (_bottom)
  106.  
  107. /*
  108.  * HIWORD and LOWORD macros, for readability.
  109.  */
  110. # define HIWORD(aLong)        (((aLong) >> 16) & 0xFFFF)
  111. # define LOWORD(aLong)        ((aLong) & 0xFFFF)
  112.  
  113. /*
  114.  * Global Data objects, used by routines external to main().
  115.  */
  116. MenuHandle        MyMenus[menuCount];     /* The menu handles */
  117. Boolean         DoneFlag;                /* Becomes TRUE when File/Quit chosen */
  118.  
  119. char *lines[500];                /* for password storage */
  120.     register
  121.         WindowPtr    myWindow;            /* Referenced often */
  122.         ControlHandle mycontrol[NCS];
  123.         ListHandle mylist=NULL;
  124.           SFReply reply;
  125.          SFTypeList tlst;
  126.          Point wh;
  127.          
  128. long mycreator = 'NCSp',mytype = 'pass';
  129. /*
  130. *  data structure for timk
  131. */
  132.     Point lastPt = {0,0},    /* last point */
  133.         csize = { 15,200 };
  134.         
  135.     Rect r1,r2,r3;
  136.     Rect rview , rframe,
  137.         dbounds ;
  138.     AppFile theFile;
  139.     char s[256],currentfile[256]={""};
  140.  
  141. char space[256];
  142. char space2[256],*p;
  143.  
  144. FILE *fout,*fin;
  145.  
  146. int nnames;
  147.  
  148. /****************************************************************************/
  149. /* passwrite
  150. *  write them out
  151. */
  152. void passwrite
  153.   (
  154.     char *s
  155.   )
  156.     {
  157.     int i;
  158.     short int vref;
  159.     FInfo finf;
  160.     Str255 vname;
  161.     
  162.     if (strlen(s) == 0)
  163.         return;
  164.  
  165.     if (NULL == (fout = fopen(s,"w"))) {
  166.         return;
  167.     }
  168.  
  169.     for (i=0; i < nnames; i++) {
  170.         fputs(lines[i],fout);
  171.         fputs("\n",fout);
  172.     }
  173.  
  174.     fclose(fout);
  175.     
  176. /*
  177. *  set correct creator and type
  178. */
  179.     getvol( &vname, &vref);
  180.     getfinfo(s, vref, &finf);
  181.     finf.fdType = mytype;
  182.     finf.fdCreator = mycreator;
  183.     setfinfo(s, vref, &finf);
  184. } /* passwrite */
  185.  
  186. /****************************************************************************/
  187. /* saveit
  188. *  Use the file picker to save out the current file
  189. */
  190. void saveit
  191.   (
  192.     void
  193.   )
  194.     {
  195.  
  196.     if (nnames <= 0)
  197.         return;
  198.         
  199.     wh.v = wh.h = 50;
  200.     sfputfile(&wh, "Save password file as:", currentfile, nil, &reply);
  201.     if (reply.good) {
  202.         setvol(0L, reply.vRefNum);
  203.         reply.fName[reply.fName[0] + 1] = 0;
  204.         passwrite(&reply.fName[1]);
  205.         strcpy(currentfile,&reply.fName[1]);
  206.     }
  207. } /* saveit */
  208.  
  209. /****************************************************************************/
  210. /* adduser
  211. *  add a new user to the list
  212. */
  213. void adduser
  214.   (
  215.     char *p
  216.   )
  217.     {
  218.     char space[256];
  219.  
  220.     lines[nnames] = NewPtr(strlen(p)+1);    /* memory copy includes the password */
  221.     strcpy(lines[nnames],p);
  222.         
  223.     strcpy(space,p);
  224.  
  225.     do {
  226.         p = strchr(space,':');
  227.         if (!p)
  228.             strcat(space,":");
  229.     } while (!p);                        /* make sure we get a : */
  230.     p++;                                /* point past : */
  231.     if (*p)
  232.         *p = '╞';
  233.     else
  234.         *p = 0;
  235.     *(++p) = 0;                            /* end string */
  236. /*
  237. *  when adding to the list manager, replace ugly password with a symbol
  238. */
  239.         LAddRow(1,nnames, mylist);
  240.         csize.h = 0; csize.v = nnames;
  241.         LSetCell(space, strlen(space), csize, mylist);
  242.         ldraw(&csize,mylist);
  243.         nnames++;
  244.     csize.h = 0; csize.v = nnames;
  245. } /* adduser */
  246.  
  247. /*****************************************************************/
  248. /* get a new user name and insert it into the list
  249. */
  250. void donewuser
  251.   (
  252.     void
  253.   )
  254.     {
  255.     DialogPtr    theDialog;
  256.     short        itemType;
  257.     Handle        itemHdl;
  258.     Rect        itemRect;
  259.     short        itemHit;
  260.  
  261.     theDialog = GetNewDialog(newuDLOG, nil, (WindowPtr) -1);
  262.     do {
  263.         ModalDialog(nil, &itemHit);
  264.         if (itemHit == 4 /* cancel */) {
  265.             DisposDialog(theDialog);
  266.             return;
  267.         }
  268.     } while (itemHit != okButton);
  269.  
  270.     GetDItem(theDialog, 3, &itemType, &itemHdl, &itemRect);
  271.     getitext(itemHdl, s);
  272.     DisposDialog(theDialog);
  273.  
  274.     if (s[0])                /* if there was a user name typed */
  275.         adduser(s);
  276.  
  277. } /* donewuser */
  278.  
  279. /****************************************************************************/
  280. /* Scompass
  281. *  compute and check the encrypted password
  282. */
  283. void Sencompass
  284.   (
  285.     char *ps,
  286.     char *en
  287.   )
  288.     {
  289.     int i,ck;
  290.     char *p,c;
  291.  
  292.     ck = 0;
  293.     p = ps;
  294.     while (*p)                /* checksum the string */
  295.         ck += *p++;
  296.  
  297.     c = ck;
  298.  
  299.     for (i=0; i<10; i++) {
  300.         *en =  (((*ps ^ c) | 32) & 127);     /* XOR with checksum */
  301.         if (*ps)
  302.             ps++;
  303.         else
  304.             c++;        /* to hide length */
  305.         en++;
  306.     }
  307.  
  308.     *en = 0;
  309. } /* Sencompass */
  310.  
  311. /****************************************************************************/
  312. /* dochoice
  313. *  prompt for a certain password
  314. */
  315. void dochoice
  316.   (
  317.     int c,
  318.     char newpass[]
  319.   )
  320.     {
  321.     char *p,*strchr();
  322.     char space[256],space2[256];
  323.  
  324.     strcpy(space,lines[c]);
  325.  
  326.     do {
  327.         p = strchr(space,':');
  328.         if (!p)
  329.             strcat(space,":");
  330.     } while (!p);                        /* make sure we get a : */
  331.  
  332.     *p = '\0';
  333.     p++;
  334.     Sencompass(newpass,space2);                /* take password */
  335.     sprintf(s,"%s:%s",space,space2);
  336.     lines[c] = NewPtr(strlen(s)+1);
  337.     strcpy(lines[c],s);                    /* this string includes passwd */
  338.     
  339.     strcat(space,":╞");                    /* indicate passwd present */
  340.     LSetCell(space, strlen(space), csize, mylist);
  341. } /* dochoice */
  342.  
  343. /*****************************************************************/
  344. /* get a new passwd and insert it into the list
  345. */
  346. int nchars;
  347. char lastpass[256];
  348.  
  349. pascal Boolean
  350. pfilt(td,tdevent,itemhit)
  351.     DialogPtr td;
  352.     EventRecord *tdevent;
  353.     short int *itemhit;
  354.     {
  355.     short        itemType;
  356.     Handle        itemHdl;
  357.     Rect        itemRect;
  358.     int c,i;
  359.     
  360.     switch(tdevent->what) {
  361.         case keyDown:
  362.         case autoKey:
  363.             if ((c = (tdevent->message & charCodeMask)) > 31) {
  364.                 if (nchars < 200)
  365.                     lastpass[nchars++] = c;
  366.                 lastpass[nchars] = 0;
  367.                 *itemhit = 2;
  368.             }
  369.             else if (c == 13) {
  370.                 *itemhit = 1;
  371.             }
  372.             else if (c == 8) {
  373.                 if (nchars > 0)
  374.                     nchars--;
  375.                 lastpass[nchars] = 0;
  376.                 *itemhit = 2;
  377.             }
  378.             GetDItem(td, 2, &itemType, &itemHdl, &itemRect);
  379.             for (i=0; i< nchars; i++)
  380.                 s[i] = '╞';
  381.             s[nchars] = 0;
  382.             setitext(itemHdl, s);
  383.             return(true);
  384.             break;
  385.         default:
  386.             break;
  387.     }
  388.     
  389.     *itemhit=0;
  390.     return(false);                
  391. } /* pfilt */
  392.  
  393. void donewpass
  394.   (
  395.     void
  396.   )
  397.     {
  398.     DialogPtr    theDialog;
  399.     short        itemType;
  400.     Handle        itemHdl;
  401.     Rect        itemRect;
  402.     short        itemHit;
  403.     char *p,*strchr();
  404.  
  405.     csize.h = csize.v = 0;
  406.     if (!LGetSelect(true, &csize, mylist)) 
  407.         return;            /* no user selected to receive passwd */
  408.         
  409.     theDialog = GetNewDialog(newpDLOG, nil, (WindowPtr) -1);
  410.     nchars = 0;
  411. /*
  412. *  set username into dialog
  413. */
  414.     GetDItem(theDialog, 5, &itemType, &itemHdl, &itemRect);
  415.     strcpy(s, lines[csize.v]);
  416.     p = strchr(s,':');                /* find ':' and truncate */
  417.     *p = 0;
  418.     setitext(itemHdl, s);
  419.     
  420.     do {
  421.         ModalDialog(pfilt, &itemHit);
  422.         if (itemHit == 3 /* cancel */) {
  423.             DisposDialog(theDialog);
  424.             return;
  425.         }
  426.     } while (itemHit != okButton);
  427.  
  428.     DisposDialog(theDialog);
  429. /*
  430. *  install the new password, it is now in lastpass
  431. *  Have to find which username it goes with first
  432. */
  433.     if (nchars < 1)
  434.         return;
  435.     
  436.     if (csize.v >= 0)
  437.         dochoice(csize.v,lastpass);    
  438.     
  439. } /* donewpass */
  440.  
  441. /****************************************************************************/
  442. /* dodelete
  443. *  remove an entry from the list manager and from the storage list
  444. */
  445. void dodelete
  446.   (
  447.     void
  448.   )
  449.     {
  450.     int i;
  451.     
  452.     csize.v = csize.h = 0;
  453.     if (LGetSelect(true, &csize, mylist)) {
  454.         LDelRow( 1, csize.v, mylist);
  455.         if (--nnames)
  456.             {
  457.             if (csize.v >= nnames)
  458.                 csize.v--;
  459.             LSetSelect(true, csize, mylist);    /* reselect next one */
  460.             for (i=csize.v; i<nnames; i++)     /* maybe deallocate mem someday? */
  461.                 lines[i] = lines[i+1];
  462.             }
  463.     }
  464. } /* dodelete */
  465.  
  466. /****************************************************************************/
  467. /* clearit
  468. *  Clear the current list
  469. *  Write the current file out if we have a current file name
  470. */
  471. void clearit
  472.   (
  473.     void
  474.   )
  475.     {
  476.     ListPtr l;        /* temp use */
  477.  
  478.     passwrite(currentfile);
  479.     
  480.     LDispose(mylist);        /* loading new list, delete old one */
  481.     
  482.     csize.h = 200; csize.v = 15;
  483.     nnames = 0;
  484.     
  485. mylist = lnew( &rview,&dbounds, &csize, 0, myWindow, true,false,false,true);
  486.     l = *mylist;
  487.     l->selFlags |= lOnlyOne;        /* only one selection at a time */
  488.  
  489.     SetPort(myWindow);            /* make my window the current port */    
  490.     EraseRect(&rframe);
  491.     InvalRect(&rframe);
  492. } /* clearit */
  493.  
  494. /****************************************************************************/
  495. /*  passlist
  496. *   List the current file
  497. */
  498. void passlist
  499.   (
  500.     char *s
  501.   )
  502.     {
  503.     char space[256];
  504.  
  505.     clearit();
  506.     strcpy(currentfile,s);
  507.     
  508.     if (NULL == (fin = fopen(s,"r"))) {
  509.         return;
  510.     }
  511.     nnames = 0;
  512.  
  513.     while (NULL != fgets(space,250,fin)) {
  514.         space[strlen(space)-1] = '\0';
  515.         adduser(space);
  516.     }
  517.     InvalRect(&rframe);        /* make it draw right */
  518.     fclose(fin);
  519. } /* passlist */
  520.  
  521. int
  522. main()
  523. {
  524.     extern void     setupMenus();
  525.     extern void     doCommand();
  526.     Rect            screenRect, dragRect;
  527.     Point            mousePt;
  528.     EventRecord     myEvent;
  529.     WindowRecord    wRecord;
  530.     WindowPtr        theActiveWindow, whichWindow;
  531.     int i;
  532.     short int shorti,shortj;
  533.     ListPtr l;        /* temp use */
  534.     /*
  535.      * Initialization traps
  536.      */
  537.     UnloadSeg(_DataInit);
  538.     InitGraf(&qd.thePort);
  539.     InitFonts();
  540.     FlushEvents(everyEvent, 0);
  541.     InitWindows();
  542.     InitMenus();
  543.     TEInit();
  544.     InitDialogs(nil);
  545.     InitCursor();
  546.     /*
  547.      * setupMenus is execute-once code, so we can unload it now.
  548.      */
  549.     setupMenus();            /* Local procedure, below */
  550.     UnloadSeg(setupMenus);
  551.     /*
  552.      * Calculate the drag rectangle in advance.
  553.      * This will be used when dragging a window frame around.
  554.      * It constrains the area to within 4 pixels from the screen edge
  555.      * and below the menu bar, which is 20 pixels high.
  556.      */
  557.     screenRect = qd.screenBits.bounds;
  558.     SETRECT(&dragRect, 20 + 4, 4, screenRect.bottom-4, screenRect.right-4);
  559.     myWindow = GetNewWindow(windowID, (Ptr) &wRecord, (WindowPtr) -1);
  560.     SetPort(myWindow);
  561. /*
  562. *  get controls
  563. */
  564.     for (i=0; i<NCS; i++)
  565.         mycontrol[i] = GetNewControl(i+129,myWindow);
  566.     HiliteControl(mycontrol[Cdelete-129], 255);
  567.     HiliteControl(mycontrol[Cpasswd-129], 255);
  568.     DrawControls(myWindow);
  569. /*
  570. *  start list manager
  571. */
  572.     SETRECT(&rview, 50,30,200,150);
  573.     SETRECT(&rframe, 49,29,201,166);
  574.     SETRECT(&dbounds, 0,0,0,1 );
  575.     
  576. mylist = lnew( &rview,&dbounds, &csize, 0, myWindow, true,false,false,true);
  577.     l = *mylist;
  578.     l->selFlags |= lOnlyOne;                        /* only one selection at a time */
  579.     FrameRect(&rframe);                                /* draw around it */
  580. /*
  581. *  if we have a selection, load it at start
  582. */
  583.     CountAppFiles( &shorti, &shortj);
  584.     if (!shorti && shortj > 0) {
  585.         GetAppFiles( shortj, &theFile);            /* get file name */
  586.         theFile.fName[theFile.fName[0] + 1] = 0;
  587.         passlist(&theFile.fName[1]);
  588.         ClrAppFiles(shortj);
  589.         strcpy(s,"Telpass: ");
  590.         strcat(s,&theFile.fName[1]);
  591.         setwtitle( myWindow, s);
  592.     }
  593.     /*
  594.      * Ready to go.
  595.      * Start with a clean event slate, and cycle the main event loop
  596.      * until the File/Quit menu item sets DoneFlag.
  597.      *
  598.      */
  599.     DoneFlag = false;
  600.     for ( ;; ) {
  601.         if (DoneFlag) {
  602.             if (!currentfile[0])    /* if untitled, save it */
  603.                 saveit();
  604.             else
  605.                 passwrite(currentfile);
  606.             LDispose(mylist);
  607.             break;        /* from main event loop */
  608.         }
  609.         /*
  610.          * Main Event tasks:
  611.          */
  612.         SystemTask();
  613.         theActiveWindow = FrontWindow();        /* Used often, avoid repeated calls */
  614.         if (myWindow == theActiveWindow) {
  615.             GetMouse(&mousePt);
  616.         }
  617.         if ( ! GetNextEvent(everyEvent, &myEvent)) {
  618.             /*
  619.              * A null or system event, not for me.
  620.              * Here is a good place for heap cleanup and/or
  621.              * segment unloading if I want to.
  622.              */
  623.             continue;
  624.         }
  625.         /*
  626.          * In the unlikely case that the active desk accessory does not
  627.          * handle mouseDown, keyDown, or other events, GetNextEvent() will
  628.          * give them to us!  So before we perform actions on some events,
  629.          * we check to see that the affected window in question is really
  630.          * our window.
  631.          */
  632.         switch (myEvent.what) {
  633.             case mouseDown:
  634.                 switch (findwindow(&myEvent.where, &whichWindow)) {
  635.                     case inSysWindow:
  636.                         SystemClick(&myEvent, whichWindow);
  637.                         break;
  638.                     case inMenuBar:
  639.                         doCommand(menuselect(&myEvent.where));
  640.                         break;
  641.                     case inDrag:
  642.                         dragwindow(whichWindow, &myEvent.where, &dragRect);
  643.                         break;
  644.                     case inGoAway:
  645.                         GlobalToLocal(&myEvent.where);
  646.                         if (trackgoaway(whichWindow, &myEvent.where))
  647.                             DoneFlag = true;
  648.                         break;
  649.                     case inGrow:
  650.                         /* There is no grow box. (Fall through) */
  651.                     case inContent:
  652.                         if (whichWindow != theActiveWindow) {
  653.                             SelectWindow(whichWindow);
  654.                         }
  655.                         GlobalToLocal(&myEvent.where);
  656.                         if (whichWindow == myWindow) {
  657.                             ControlHandle tempc;
  658.                             findcontrol(&myEvent.where,myWindow,&tempc);
  659.                             if (tempc)
  660.                                 if (trackcontrol(tempc, &myEvent.where, NULL)) {
  661.                                 /* find which one */
  662.                                 for (i=0; i<NCS; i++)
  663.                                     if (tempc == mycontrol[i])
  664.                                         switch (i+129) {
  665.                                             case Cnewuser:
  666.                                                 donewuser();
  667.                                                 break;
  668.                                             case Cpasswd:
  669.                                                 donewpass();
  670.                                                 break;
  671.                                             case Cdelete:
  672.                                                 dodelete();
  673.                                                 break;
  674.                                             default:
  675.                                             break;
  676.                                         }
  677.                                         
  678.                                 }
  679.                             /*
  680.                             * check in list manager
  681.                             */
  682.                             if (ptinrect(&myEvent.where, &rframe)) {
  683.                                 lclick(&myEvent.where, myEvent.modifiers, mylist);
  684.                             }
  685.                 /* if something selected, highlight options, if not, dehighlight */
  686.                             csize.h = csize.v = 0;
  687.                             if (LGetSelect(true, &csize, mylist)) {
  688.                                 HiliteControl(mycontrol[Cdelete-129], 0);
  689.                                 HiliteControl(mycontrol[Cpasswd-129], 0);
  690.                             }
  691.                             else {
  692.                                 HiliteControl(mycontrol[Cdelete-129], 255);
  693.                                 HiliteControl(mycontrol[Cpasswd-129], 255);
  694.                             }
  695.                         }
  696.                         break;
  697.                     default:
  698.                         break;
  699.                 }/*endsw findwindow*/
  700.                 break;
  701.  
  702.             case keyDown:
  703.             case autoKey:
  704.                 if (myWindow == theActiveWindow) {
  705.                     if (myEvent.modifiers & cmdKey) {
  706.                         doCommand(MenuKey(myEvent.message & charCodeMask));
  707.                     } else {
  708.                         if ('x' == (char) (myEvent.message & charCodeMask))
  709.                             DoneFlag = true;
  710.                     }
  711.                 }
  712.                 break;
  713.  
  714.             case activateEvt:
  715.                 if ((WindowPtr) myEvent.message == myWindow) {
  716.                     LActivate(myEvent.modifiers & activeFlag, mylist);
  717.                 }
  718.                 break;
  719.  
  720.             case updateEvt:
  721.                 if ((WindowPtr) myEvent.message == myWindow) {
  722.                     BeginUpdate(myWindow);
  723.                     DrawControls(myWindow);
  724.                     FrameRect(&rframe);
  725.                     LUpdate(myWindow->visRgn,mylist);
  726.                     EndUpdate(myWindow);
  727.                 }
  728.                 break;
  729.  
  730.             default:
  731.                 break;
  732.  
  733.         }/*endsw myEvent.what*/
  734.  
  735.     }/*endfor Main Event loop*/
  736.     /*
  737.      * No cleanup required, but if there was, it would happen here.
  738.      */
  739.     return(0);        /* Return from main() to allow C runtime cleanup */
  740. }
  741.  
  742. /*
  743.  * Set the segment to Initialize.  BEWARE: leading and trailing white space
  744.  * would be part of the segment name!
  745.  */
  746. #pragma segment Initialize
  747.  
  748. /*
  749.  * Set up the Apple, File, and Edit menus.
  750.  * If the MENU resources are missing, we die.
  751.  */
  752. void
  753. setupMenus()
  754. {
  755.     extern MenuHandle    MyMenus[];
  756.     register MenuHandle *pMenu;
  757.     /*
  758.      * Set up the desk accessories menu.
  759.      * The "About Sample..." item, followed by a grey line,
  760.      * is presumed to be already in the resource.  We then
  761.      * append the desk accessory names from the 'DRVR' resources.
  762.      */
  763.     MyMenus[appleMenu] = GetMenu(appleID);
  764.     AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
  765.     /*
  766.      * Now the File and Edit menus.
  767.      */
  768.     MyMenus[fileMenu] = GetMenu(fileID);
  769.     MyMenus[editMenu] = GetMenu(editID);
  770.     /*
  771.      * Now insert all of the application menus in the menu bar.
  772.      */
  773.     for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
  774.         InsertMenu(*pMenu, 0);
  775.     }
  776.  
  777.     DrawMenuBar();
  778.  
  779.     return;
  780. }
  781.  
  782. /*
  783.  * Back to the Main segment.
  784.  */
  785. #pragma segment Main
  786.  
  787. showAboutMeDialog()
  788. {
  789.     DialogPtr    theDialog;
  790.     short        itemHit;
  791.  
  792.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  793.     do {
  794.         ModalDialog(nil, &itemHit);
  795.     } while (itemHit != okButton);
  796.  
  797.     DisposDialog(theDialog);
  798.  
  799.     return;
  800. }
  801.  
  802. /*
  803.  * Process mouse clicks in menu bar
  804.  */
  805. void
  806. doCommand(mResult)
  807. long mResult;
  808. {
  809.     extern MenuHandle    MyMenus[];
  810.     extern Boolean        DoneFlag;
  811.     int                 theMenu, theItem;
  812.     char                daName[256];
  813.     GrafPtr             savePort;
  814.  
  815.     theItem = LOWORD(mResult);
  816.     theMenu = HIWORD(mResult);        /* This is the resource ID */
  817.  
  818.     switch (theMenu) {
  819.         case appleID:
  820.             if (theItem == aboutMeCommand) {
  821.                 showAboutMeDialog();
  822.             } else {
  823.                 getitem(MyMenus[appleMenu], theItem, daName);
  824.                 GetPort(&savePort);
  825.                 (void) opendeskacc(daName);
  826.                 SetPort(savePort);
  827.             }
  828.             break;
  829.  
  830.         case fileID:
  831.             switch (theItem) {
  832.                 case openCommand:
  833.                     if (strlen(currentfile) > 0)
  834.                         passwrite(currentfile);
  835.                     wh.h = wh.v = 50;
  836.                     tlst[0] = mytype;
  837.                     sfgetfile(&wh, "Select password file", nil, 1, tlst,
  838.                               nil, &reply);
  839.                     if (reply.good) {
  840.                         setvol(0L, reply.vRefNum);
  841.                         reply.fName[reply.fName[0] + 1] = 0;
  842.                         passlist(&reply.fName[1]);        /* load this file */
  843.                     }
  844.                     
  845.                     break;
  846.                 case saveCommand:
  847.                 case newCommand:
  848.                     if (strlen(currentfile) > 0)
  849.                         passwrite(currentfile);
  850.                     else
  851.                         saveit();
  852.                     if (theItem == newCommand) {
  853.                         clearit();
  854.                         currentfile[0] = 0;
  855.                         setwtitle( myWindow, "Telpass: Untitled");
  856.                     }
  857.                     break;
  858.                 case saveasCommand:
  859.                     saveit();
  860.                     break;
  861.                 case quitCommand:
  862.                     DoneFlag = true;            /* Request exit */
  863.                     break;
  864.                 default:
  865.                     break;
  866.             }
  867.             if (strlen(currentfile) > 0) {
  868.                 strcpy(s,"Telpass: ");
  869.                 strcat(s,currentfile);
  870.                 setwtitle( myWindow, s);
  871.             }
  872.             break;
  873.         case editID:
  874.             /*
  875.              * If this is for a 'standard' edit item,
  876.              * run it through SystemEdit first.
  877.              * SystemEdit will return FALSE if it's not a system window.
  878.              */
  879.             if ((theItem <= clearCommand) && SystemEdit(theItem-1)) {
  880.                 break;
  881.             }
  882.             /*
  883.              * Otherwise, it's my window.
  884.              */
  885.             switch (theItem) {
  886.                 case undoCommand:
  887.                     break;
  888.                 case cutCommand:
  889.                 case copyCommand:
  890.                     ZeroScrap();
  891.                     break;
  892.                 case pasteCommand:
  893.                     break;
  894.                 case clearCommand:
  895.                     break;
  896.                 default:
  897.                     break;
  898.             } /*endsw theItem*/
  899.             break;
  900.  
  901.         default:
  902.             break;
  903.  
  904.     }/*endsw theMenu*/
  905.  
  906.     HiliteMenu(0);
  907.  
  908.     return;
  909. }
  910.